/*
 * @lc app=leetcode.cn id=165 lang=cpp
 *
 * [165] 比较版本号
 */

// @lc code=start
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
    inline vector<int> split(const string &s)
    {
        vector<int> ans;
        int start = 0;
        int t = s.find_first_of('.', start);

        while (start < s.size())
        {
            if (t == s.npos)
                t = s.size();
            ans.push_back(stoi(s.substr(start, t - start)));
            start = t + 1;
            t = s.find_first_of('.', start);
        }
        return ans;
    }
    int compareVersion(string version1, string version2)
    {
        vector<int> v1 = split(version1);
        vector<int> v2 = split(version2);
        int i = 0;
        for (; i < v1.size() && i < v2.size(); ++i)
        {
            if (v1[i] > v2[i])
                return 1;
            else if (v1[i] < v2[i])
                return -1;
        }
        while (i < v1.size())
        {
            if (v1[i])
                return 1;
            ++i;
        }
        while (i < v2.size())
        {
            if (v2[i])
                return -1;
            ++i;
        }
        return 0;
    }
};

// int main()
// {
//     cout << Solution().compareVersion("1.0.1", "1") << endl;
//     return 0;
// }

// @lc code=end
